<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    String id=request.getParameter("a");
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:choose>
    <c:when test="${list==null}">

        <jsp:forward page="/Book/index"></jsp:forward>

    </c:when>
    <c:otherwise>


        <html>

        <head>
            <base href="<%=basePath %>">
            <title>Title</title>
        </head>
        <body>
        <div style="width:600px;margin: auto">
            <form action="Book/index" method="post" >
                <select name="a">
                    <option value ="0"> </option>
                    <option value ="1" <c:if test="${a==1}">selected</c:if>>书名</option>
                    <option value="2" <c:if test="${a==2}">selected</c:if>>作者</option>
                    <option value="3" <c:if test="${a==3}">selected</c:if>>出版社</option>
                </select>
                <input type="text" name="b" value="${b}"/>
                <input type="submit" value="搜索"/>
            </form>

            <table border="1" width="80%">
                <tr><th colspan="6"><a href="Book/add" style='color:red'>增加书籍</a></th ></tr>
                <tr style="background-color: blue">
                    <th>书名</th>
                    <th>作者</th>
                    <th>出版社</th>
                    <th>页数</th>
                    <th>价格</th>
                    <th>操作</th>
                    <th>删除</th>
                </tr>

                <c:forEach items="${list}" var="book">
                    <tr>
                        <td>${book.bookName}</td>
                        <td>${book.bookAuthor}</td>
                        <td>${book.bookPublish}</td>
                        <td>${book.bookPage}</td>
                        <td>${book.bookPrice}</td>
                        <td><a href="Book/selById?bookId=${book.bookId}">修改</a></td>
                        <td><a href="Book/delect?bookId=${book.bookId}">删除</a></td>
                    </tr>
                </c:forEach>

            </table>

            <div class="pages">
                <c:if test="${page.currPageNo>1}">
                    <a href="Book/index?pageIndex=1&a=${a}&b=${b}" class="p_pre" >首页</a>
                    <a href="Book/index?pageIndex=${page.currPageNo-1}&a=${a}&b=${b}">上一页</a>
                </c:if>
                &nbsp;&nbsp;  &nbsp;&nbsp;
                <c:if test="${page.currPageNo < page.totalPageCount }">
                    <a href="Book/index?pageIndex=${page.currPageNo+1}&a=${a}&b=${b}">下一页</a>
                    &nbsp;&nbsp;
                    <a href="Book/index?pageIndex=${page.totalPageCount}&a=${a}&b=${b}">末页</a>
                </c:if>
                &nbsp;&nbsp;  &nbsp;&nbsp;
                <span>第${page.currPageNo}页/共${page.totalPageCount}页</span>
            </div>

        </div>
        <div>
            <c:if test="${result>0}">
                <span style="color: red">添加成功</span>
            </c:if>
            <c:if test="${result<=0}">
                <span style="color: red">添加失败</span>
            </c:if>
        </div>
        </body>
        </html>
    </c:otherwise>
</c:choose>